<template>
  <div class="component-root-container">
    <el-header>
      <el-form ref="projectRule" :rules="projectRule" :model="project" label-width="120px" label-position="right">
        <el-row>
          <el-col :span="8">
            <el-form-item label="合同编码:" prop="contractNo">
              <el-input v-model="project['contractNo']" placeholder="请输入" @input="change($event)" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单据编号:" prop="orderNo">
                <el-input v-model="project['orderNo']" placeholder="请输入" @input="change($event)" clearable />
            </el-form-item>
          </el-col>
            <el-col :span="8" >
            <el-form-item label="单据类型:" prop="orderType">
              <el-select v-model="project['orderType']" placeholder="请选择" filterable clearable>
                <el-option v-for="item in orderTypes" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8" >
            <el-form-item label="订单操作类型:" prop="operationType">
              <el-select v-model="project['operationType']" placeholder="请选择" filterable clearable>
                <el-option v-for="item in optiorderOptionsons" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
            <el-col :span="8">
            <el-form-item label="校验规则编号:" prop="ruleNo">
                 <el-input v-model="project['ruleNo']" @input="change($event)" clearable  />
                
            </el-form-item>
          </el-col>
            <el-col :span="8" class="col_button">
            <div class="button">
              <el-button class="query" @click="buttonClick">
              查询
              </el-button>
              <el-button class="query" @click="reset">
                重置
              </el-button>
            </div>
            
          </el-col>
        </el-row>
      </el-form>
    </el-header>

    <el-main>
      <div class="contentInfo" style="margin-bottom:20px;">
        <el-row>
          <el-col class="header-title">
            <span class="header-vertical" />
            场景使用情况
          </el-col>
        </el-row>
        <el-row>
          <div class="inline">
            <div><span>调用次数/日：</span><span>{{ queryCount }}</span></div>
            <div><a class="link" href="javascript:;" @click="$router.push({name:'biz-ml'})">详情</a></div>
          </div>
        </el-row>
      </div>
      <div class="contentInfo">
        <el-row>
          <el-col class="header-title">
            <span class="header-vertical" />
            场景说明
          </el-col>
        </el-row>
        <el-row>
          <div class="page-tip">
            <div class="description">商合交易、认证、仓储推送单据给财务、以及财务接收单据时，将单据合同信息与公共库以及合同系统信息进行校验。</div>
          </div>
          <div class="page-tip row_bg">
            <div class="params-tip"><span>示例参数</span>
              合同编码：CTC-HYHY-2022-000036, 单据编号：PO-jtjcse-SP4120221109164510005026811, 单据类型：线下直接采购订单, 订单操作类型：正常数据, 校验规则编号：1,2,3,4,5,6,7,8,9,10;
</div>
          </div>
          
        </el-row>
      </div>
    </el-main>
    <el-main>
      <div class="contentInfo">
        <el-row>
          <el-col class="header-title">
            <span class="header-vertical" />
            校验结果
          </el-col>
        </el-row>
        <el-row>
          <div class="page-tip">
            <div class="description">
              <!-- <div> {{ dialog.title }} </div> -->
              <el-row v-for="(item,index) in dialog.content" :key="index" class="dialog-row">
                <el-col>
                  {{ item.returnMsg }}
                </el-col>
              </el-row>
            </div>
          </div>
        </el-row>
      </div>
    </el-main>

  </div>


</template>

<script>
  export default {
    data() {
      return {
        dialogVisible: false,
        queryCount:0,
        project: {
            contractNo: '',
            orderNo: '',
            orderType: '',
            operationType: '',
            ruleNo:''
        },
        dialog: {
          title: '',
          content: []
        },
        optiorderOptionsons: [
          {
            label: '正常数据',
            value: '1'
          },
          {
            label: '回滚数据',
            value: '2'
          }
        ],
        orderTypes: [
          {
            label: '线下直接采购订单',
            value: '02'
          },
          {
            label: '线下批量采购订单',
            value: '04'
          },
          {
            label: '线下综合物资采购',
            value: '12'
          },
          {
            label: '线下设计',
            value: '14'
          },
          {
            label: '线下监理',
            value: '15'
          }
        ],
        projectRule: {
          contractNo: [{
            required: true,
            message: '请输入合同编号',
            trigger: 'blur'
          }],
          orderNo: [{
            required: true,
            message: '请输入单据编号',
            trigger: 'blur'
          }],
          orderType: [{
            required: true,
            message: '请选择单据类型',
            trigger: 'blur'
          }],
          operationType: [{
            required: true,
            message: '请选择订单操作类型',
            trigger: 'blur'
          }],
          ruleNo: [{
            required: true,
            message: '请输入校验规则编号',
            trigger: 'blur'
          }]

        }
      }
    },
    created() {
      this.queryPageCount('3.2');
    },
    mounted() {},
    computed: {},
    methods: {
      async buttonClick() {
        try {
          this.dialog = {
            title: '',
            content: []
          }

          await this.$refs['projectRule'].validate()
          // update by kxd on 20230406
          //const data = [{
          //   contractNo: this.project['contractNo'],
          //     orderNo: this.project['orderNo'],
          //     orderType: this.project['orderType'],
          //     operationType: this.project['operationType'],
          //     ruleNo: this.project['ruleNo']
          // }]

          const data = {
            contractNo: this.project['contractNo'],
              orderNo: this.project['orderNo'],
              orderType: this.project['orderType'],
              operationType: this.project['operationType'],
              ruleNo: this.project['ruleNo']
          }

          const r = await this.$http({
            url: this.$http.adornBizUrl('/phase/three/contract/rule/pre/check'),
            method: 'post',
            data: this.$http.adornData('param=' + JSON.stringify(data), false),
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
            }
          })
          console.log(r.data);
          if (r.data.resultStat ==="000") {
            // console.log(r.data.data.retiurnMsg)
            this.dialog.content = r.data.data
            
            // this.dialog.title = r.data.data.retiurnMsg
          }else{
              this.dialog.title = r.data.mess
          }
          this.dialogVisible = true
        } catch (e) {
          console.log(e)
        } finally {
          this.listLoading = false
        }
      },
      getTitle(key) {
        const option = this.options.filter(o => o.key === key)
        let value = null
        if (option[0]) {
          value = option[0].value
        }
        return value
      },
      reset() {
        this.project = {
          prjCode: '',
          operationId: ''
        }

        this.dialog = {
          title: '',
          content: []
        }
        this.$refs['projectRule'].clearValidate();
      },
      change(e) {
        this.$forceUpdate()
      },

      async queryPageCount(scene) {
        try {
          const r = await this.$http({
            url: this.$http.adornBizUrl('/log/queryStatistics'),
            method: 'post',
            data: this.$http.adornData('param=' + JSON.stringify({scene:scene}), false),
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
            }
          })
          if(r.data.data && r.data.data.length >0){
              var result = r.data.data[0];
              this.queryCount=result.cnt||'0';
          }
        } catch (e) {
          console.log(e)
        } finally {
        }
      }
    }
  }
</script>

<style scoped lang="scss">
  @import "../../../assets/scss/formatQueryPage";
  @include formatQueryPage(120px);
  .el-input, .el-select {
    width: 60%;
  }


  .query {
    color: rgba(255, 255, 255, 1);
    background: rgba(235, 75, 75, 1);
    border-radius: 6px;
    border-color: rgba(235, 75, 75, 1);
  }

  .custom-button {
    display: flex;
    justify-content: center;
  }

  .dialog-row {
    margin-bottom: 5px;
  }
</style>
